<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Widgets for displaying a list of photos related to the photo set.
 * Includes a list widget and its specific item widget.
 * 
 * Show the items in the list, and some reaction button as 'delete'.
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.2
 * 
 * 0.2)  Inherited from Grid.
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_grid.php';

// Definitions.
define('EDITPHOTOSLIST_THUMBNAIL_MAXWIDTH',			128);
define('EDITPHOTOSLIST_THUMBNAIL_MAXHEIGHT',		128);

/**
 * Widget for displaying a grid of photos.
 */
class ChangePhotosetGrid extends Grid
{
	/**
	 * Overrided.
	 * Starts a grid.
	 */
	function showStart()
	{
		$this->out->elementStart('ol', array('class' => 'cls_ol_grid'));
	}
	
	/**
	 * Ends a list.
	 */
	function showEnd()
	{
		$this->out->elementEnd('ol');
	}

	/**
	 * Returns a new grid item for the current photo.
	 */
	function newListItem(&$obj)
	{
		return new ChangePhotosetGridItem($obj, $this->out);
	}
}

/**
 * Widget for displaying a single photo item with some options.
 */
class ChangePhotosetGridItem extends BaseGridItem
{
	/**
	 * Overrided.
	 */
	function showStart()
	{
		$this->out->elementStart('li');
		$this->out->elementStart('div', 'cls_div_girditem');
	}
	
	function showEnd()
	{
		$this->out->elementEnd('div');
		$this->out->elementEnd('li');
	}
	
	function showDataInfo()
	{
		$this->out->elementStart('div', array('class' => 'cls_div_thumnailwrapper'));
		$this->out->elementStart('a', array('href' => $this->obj->photourl(),
											'target' => '_blank'));		
		$this->out->element('img', array('src'		 => $this->obj->thumbnailurl(),
										 'max-width' => EDITPHOTOSLIST_THUMBNAIL_MAXWIDTH,
										 'max-height'=> EDITPHOTOSLIST_THUMBNAIL_MAXHEIGHT));
		$this->out->elementEnd('a');
		$this->out->elementEnd('div');
	}
	
	function showOptions()
	{
		$this->out->elementStart('div', 'cls_div_chnagephotosetoptions');
		
// TODO: Check if has rights to delete or more options.
			if (true) {
			$this->out->element('a', array('href' => slh_action2url('deletephoto',
								  	   							  	array('gphoto_id' => $this->obj->id)),
										   'title'=> '把这张图片删掉哈!'),
								'删除');
			}
		$this->out->elementEnd('div');
	}
}

?>